package com.vvlive.caibao.smartcity.ui;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.animation.DecelerateInterpolator;

import com.eftimoff.androidplayer.Player;
import com.eftimoff.androidplayer.actions.property.PropertyAction;
import com.eftimoff.androidplayer.listeners.PlayerEndListener;
import com.eftimoff.androidplayer.listeners.PlayerStartListener;

import smartcity.vvlive.caibao.com.smartc.R;

public class MainActivity extends Activity {
    private SharedPreferences msharedPreferences;
    String Mark = "";
    Intent intent = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        final View g_bg = findViewById(R.id.g_bg_img);
        final View g_smart_icon = findViewById(R.id.smart_ico);
        final View smart_text = findViewById(R.id.smart_text);
        animateSampleThree(g_bg, g_smart_icon, smart_text);
    }

    private void animateSampleThree(View... views) {
        final PropertyAction g_bg_animate = PropertyAction.newPropertyAction(views[0]).translationY(200).duration(1000).alpha(0f).build();
        final PropertyAction smart_txt_bottom = PropertyAction.newPropertyAction(views[2]).interpolator(new DecelerateInterpolator()).translationY(200).duration(1000).delay(300).alpha(0.4f).build();
        final PropertyAction g_smart_icon = PropertyAction.newPropertyAction(views[1]).rotation(-180).scaleX(0.1f).scaleY(0.1f).translationX(-200).delay(500).build();


        Player.init().setPlayerStartListener(playerStartListener).
                                                                         setPlayerEndListener(playerEndListener)
                .animate(g_bg_animate)
                .animate(g_smart_icon)
                .then()
                .animate(smart_txt_bottom)
                .play();

    }

    /**
     * 动画开始的监听
     */
    protected PlayerStartListener playerStartListener = new PlayerStartListener() {
        @Override
        public void onStart() {


        }
    };
    /**
     * 动画结束的监听
     */
    protected PlayerEndListener playerEndListener = new PlayerEndListener() {
        @Override
        public void onEnd() {
            msharedPreferences = getSharedPreferences("mark", 0);
            Mark = msharedPreferences.getString("mark", "");
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(350);
                        if (Mark == "" || "".equals(Mark)) {
                            intent = new Intent(com.vvlive.caibao.smartcity.ui.MainActivity.this, GuideActivity.class);

                        } else {
                            intent = new Intent(com.vvlive.caibao.smartcity.ui.MainActivity.this, IndexFragmentActivity.class);
                        }
                        startActivity(intent);
                        finish();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }
    };
}
